<template>
  <div class="grand-child">
    <h3>我是孙组件</h3>
    <h4>银子:{{ money }}</h4>
    <h4>车子:一辆{{ car.brand }},价格是:{{ car.price }}万元</h4>

    <button @click="updateMoney(5)">花爷爷的钱</button>
  </div>
</template>

<script setup lang="ts" name="GrandChild">
// inject有注射，注入的意思
import { inject } from "vue";

/**
 * 注意： 当父亲没有传递给你指定的值的时候，inject的第二个参数才会触发，也就是默认值
 */
const { money, updateMoney } = inject("moneyContext", {
  money: 6,
  updateMoney: (x: number) => {},
});

const car = inject("car", { brand: "宝马", price: 600 });
</script>

<style scoped>
.grand-child {
  background-color: orange;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px black;
}
</style>
